package yt.kpool.fragment;

import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import com.github.mikephil.charting.charts.LineChart;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yt.kpool.MainActivity;
import yt.kpool.R;
import yt.kpool.activity.personal.FastLookActivity;
import yt.kpool.base.BaseApplication;
import yt.kpool.bean.ChildAccountBean;
import yt.kpool.bean.CurrencyList;
import yt.kpool.bean.LineChartTestBean;
import yt.kpool.bean.MinerCharBean;
import yt.kpool.bean.PoolAccountInfoBean;
import yt.kpool.bean.PoolCoinDetailsBean;
import yt.kpool.interfac.Observer;
import yt.kpool.interfac.OnSelectPersonListener;
import yt.kpool.network.HttpUtils;
import yt.kpool.network.MyGson;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.DynamicLineChartManager;
import yt.kpool.util.NetWorkUtil;
import yt.kpool.util.SPUtil;
import yt.kpool.util.TextSwitcherAnimation;
import yt.kpool.util.TimeUtil;
import yt.kpool.util.ToastUtil;
import yt.kpool.util.Util;
import yt.kpool.util.imageUtil.GlideUtil;
import yt.kpool.view.MyGridView;
import yt.kpool.view.dialog.ErrorDialog;
import yt.kpool.view.dialog.LoadingDialog;
import yt.kpool.view.lazyviewpager.LazyFragmentPagerAdapter;
import yt.kpool.view.pop.CurrencyPopupWindow;

import static android.content.Context.CLIPBOARD_SERVICE;

/**
 * 矿池
 */
public class OrePoolFragment extends Fragment implements LazyFragmentPagerAdapter.Laziable, Observer {

    @BindView(R.id.textSwitcher)
    TextSwitcher textSwitcher;
    @BindView(R.id.mywitcher)
    Switch mywitcher;
    @BindView(R.id.tv_minue)
    TextView tv_minue;
    @BindView(R.id.tv_day)
    TextView tv_day;
    @BindView(R.id.tv_address1)
    TextView tv_address1;
    @BindView(R.id.tv_address2)
    TextView tv_address2;
    @BindView(R.id.tv_address3)
    TextView tv_address3;
    @BindView(R.id.ll_address2)
    LinearLayout ll_address2;
    @BindView(R.id.ll_address3)
    LinearLayout ll_address3;
//    @BindView(R.id.v_address2)
//    View v_address2;
//    @BindView(R.id.v_address3)
//    View v_address3;

    @BindView(R.id.tv_person)
    TextView tv_person;
    @BindView(R.id.dynamic_chart2)
    LineChart mChart2;


    private DynamicLineChartManager dynamicLineChartManager2;
    private OnSelectPersonListener onSelectPersonListener;// 挖币账户选择
    private int childaccountId;

    //币种
    @BindView(R.id.tv_currrncyname)
    TextView tv_currrncyname;
    @BindView(R.id.iv_curreney)
    ImageView iv_curreney;
    @BindView(R.id.ll_currency)
    LinearLayout ll_currency;
    @BindView(R.id.tv_unit)
    TextView tv_unit;
    @BindView(R.id.tv_Prompt)
    TextView tv_Prompt;

    @BindView(R.id.ll_Prompt)
    LinearLayout ll_Prompt;
    @BindView(R.id.tv_NetworkHashrate)
    TextView tv_NetworkHashrate;
    @BindView(R.id.tv_PoolHashrate)
    TextView tv_PoolHashrate;
    @BindView(R.id.tv_NetworkDifficulty)
    TextView tv_NetworkDifficulty;
    @BindView(R.id.tv_Price)
    TextView tv_Price;
    @BindView(R.id.tv_CostRate)
    TextView tv_CostRate;
    @BindView(R.id.tv_StartPayAmount)
    TextView tv_StartPayAmount;
    @BindView(R.id.tv_Throughput)
    TextView tv_Throughput;
    @BindView(R.id.tv_dayunit)
    TextView tv_dayunit;

    @BindView(R.id.btn_fastlook)
    Button btn_fastlook;
    @BindView(R.id.iv_account)
    ImageView iv_account;

    @BindView(R.id.tv_PayTime)
    TextView tv_PayTime;


    @BindView(R.id.tv_OffMinerNumber)
    TextView tv_OffMinerNumber;
    @BindView(R.id.tv_onlinenum)
    TextView tv_onlinenum;
    @BindView(R.id.tv_Hashrate24H)
    TextView tv_Hashrate24H;
    @BindView(R.id.tv_Profit24H)
    TextView tv_Profit24H;
    @BindView(R.id.tv_Hashrate24Hunit)
    TextView tv_Hashrate24Hunit;
    @BindView(R.id.tv_Balance)
    TextView tv_Balance;
    @BindView(R.id.tv_unit1)
    TextView tv_unit1;
    @BindView(R.id.tv_unit2)
    TextView tv_unit2;


    private CurrencyPopupWindow currencyPopupWindow;//币种选择
    private int currencyId;//币种id
    private List<CurrencyList.DataBean> currencyListData;
    private LoadingDialog loadingDialog;

    private PoolCoinDetailsBean.DataBean dataBean;
    private SPUtil spUtil;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg_orepool, container, false);
        ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        loadingDialog = new LoadingDialog(getActivity(), 0);
        spUtil = new SPUtil(getActivity(), "fileName");
        init();
        initTextSwitcher();

        initSwitcher();

        initAccount();


        currencyId = onSelectPersonListener.getCurrencyId();

        getCurrrencyData();

    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = false, priority = 0)
    public void handleData(String str) {
        Log.i("-->", "================" + str);
        if (str.equals("123")) {
            getData();
        }


    }

    private void init() {

        EventBus.getDefault().register(this);
        List<LineChartTestBean> list = new ArrayList<>();

        String unit = "";
        float max = 6;
        for (int i = 0; i < 49; i++) {
            if (i == 0) {
                unit = "T";
            }
            list.add(new LineChartTestBean("", 0f));

        }
        List<String> names = new ArrayList<>(); //折线名字集合
        List<Integer> colour = new ArrayList<>();//折线颜色集合
        //折线名字 //折线颜色
        names.add("矿工");
        colour.add(getResources().getColor(R.color.white));
        tv_unit.setText("" + unit);
        dynamicLineChartManager2 = new DynamicLineChartManager(mChart2, names, colour, 48, unit);
        dynamicLineChartManager2.setDescription("");
        dynamicLineChartManager2.setYAxis(max, 0, 6);
        for (int i = 0; i < list.size(); i++) {
            dynamicLineChartManager2.addEntry(list.get(i));
        }

    }

    private void initAccount() {
        if (onSelectPersonListener.getIsFastLogin()) {
            //快速登录
            btn_fastlook.setText("返回登录账号");
            iv_account.setImageDrawable(getActivity().getResources().getDrawable(R.mipmap.daohang2));
            childaccountId = onSelectPersonListener.childAccountId();
            tv_person.setText(onSelectPersonListener.childAccountName() + " （只读页面）");
        } else {
            btn_fastlook.setText("快速查看");
            iv_account.setImageDrawable(getActivity().getResources().getDrawable(R.mipmap.daohang));

            if (onSelectPersonListener.getchildAccountType() == 1) {
                childaccountId = MainActivity.TOTALID;
                tv_person.setText("合计");
            } else {
                childaccountId = onSelectPersonListener.childAccountId();
                tv_person.setText(onSelectPersonListener.childAccountName());
            }
        }
    }

    /**
     * 获取币种数据
     */
    private void getCurrrencyData() {
        currencyListData = new ArrayList<>();
        if (NetWorkUtil.check(getActivity())) {
            loadingDialog.show();

            NetHelperNew.GetCurrencyList(new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                    loadingDialog.dismiss();
                    Log.i("-->", "币种列表：" + data);
                    CurrencyList currencyList = MyGson.getInstance().fromJson(data, CurrencyList.class);
                    if (currencyList.getType() == 1) {

                        currencyListData.addAll(currencyList.getData());
                        initCurrencyPopupWindow();
                        if (currencyList.getData().size() > 0) {
                            if (currencyId == 0) {
                                GlideUtil.loadImage(getActivity(), NetHelperNew.URL + currencyList.getData().get(0).getIcon(), iv_curreney, R.mipmap.failimage, R.mipmap.failimage);
                                tv_currrncyname.setText(currencyList.getData().get(0).getCode().toUpperCase());
                                currencyId = currencyList.getData().get(0).getId();
                                onSelectPersonListener.selectCurrency(currencyId);
                            } else {

                                for (int i = 0; i < currencyList.getData().size(); i++) {
                                    if (currencyId == currencyList.getData().get(i).getId()) {
                                        GlideUtil.loadImage(getActivity(), NetHelperNew.URL + currencyList.getData().get(i).getIcon(), iv_curreney, R.mipmap.failimage, R.mipmap.failimage);
                                        tv_currrncyname.setText(currencyList.getData().get(i).getCode().toUpperCase());
                                    }
                                }
                            }
                        }
                        getData();
                    } else {
                        new ErrorDialog(getContext(), currencyList.getContent()).show();
                    }
                }

                @Override
                public void onError(String msg) {
                    super.onError(msg);
                    loadingDialog.dismiss();

                    ToastUtil.showToast(getActivity(), msg);
                }
            });


        }

    }

    /**
     * 币种选择pop初始化
     */
    private void initCurrencyPopupWindow() {
        currencyPopupWindow = new CurrencyPopupWindow(currencyListData, getActivity(), new CurrencyPopupWindow.OnSeleCurrencyLayoutListener() {
            @Override
            public void selectHouseLayout(int i) {
                currencyId = currencyListData.get(i).getId();
                GlideUtil.loadImage(getActivity(), NetHelperNew.URL + currencyListData.get(i).getIcon(), iv_curreney, R.mipmap.failimage, R.mipmap.failimage);
                tv_currrncyname.setText(currencyListData.get(i).getCode().toUpperCase());
                onSelectPersonListener.selectCurrency(currencyId);
                getData();
            }
        });
    }

    /**
     * 获取图表网络数据
     */
    private void getData() {

        if (NetWorkUtil.check(getActivity())) {
            loadingDialog.show();
            NetHelperNew.GetOwnMinersChart("" + childaccountId, "" + currencyId, "", new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                    Log.i("-->", "矿工图表数据：" + data);
                    loadingDialog.dismiss();
                    MinerCharBean minerBean = MyGson.getInstance().fromJson(data, MinerCharBean.class);


                    if (minerBean.getType() == 1) {
                        List<MinerCharBean.DataBean> dataBeans = minerBean.getData();
                        List<LineChartTestBean> list = new ArrayList<>();

                        String unit = "";
                        float max = 0;
                        for (int i = 0; i < dataBeans.size(); i++) {
                            if (i == 0) {
                                unit = dataBeans.get(i).getHashrateUnit();
                            }
                            try {
                                list.add(new LineChartTestBean(TimeUtil.dealDateFormatNomm(dataBeans.get(i).getCreatedTime()), (float) dataBeans.get(i).getHashrate()));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            if (dataBeans.get(i).getHashrate() > max) {
                                max = (float) dataBeans.get(i).getHashrate();
                            }
                        }


                        List<String> names = new ArrayList<>(); //折线名字集合
                        List<Integer> colour = new ArrayList<>();//折线颜色集合
                        //折线名字 //折线颜色
                        names.add("矿工");
                        colour.add(getResources().getColor(R.color.white));


                        tv_unit.setText("" + unit);
                        dynamicLineChartManager2 = new DynamicLineChartManager(mChart2, names, colour, 48, unit);
                        dynamicLineChartManager2.setDescription("");
                        dynamicLineChartManager2.setYAxis(max, 0, 6);
                        for (int i = 0; i < list.size(); i++) {
                            dynamicLineChartManager2.addEntry(list.get(i));
                        }
                    } else {

                        new ErrorDialog(getActivity(), minerBean.getContent()).show();
                    }
                }

                @Override
                public void onError(String msg) {
                    super.onError(msg);

                    loadingDialog.dismiss();
                    ToastUtil.showToast(getActivity(), msg);
                }
            });

        }


        //矿池详细信息
        if (NetWorkUtil.check(getActivity())) {

            NetHelperNew.PoolCoinDetails("" + currencyId, "" + childaccountId, new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                    Log.i("-->", "矿池详情数据：" + data);

                    PoolCoinDetailsBean poolCoinDetailsBean = MyGson.getInstance().fromJson(data, PoolCoinDetailsBean.class);


                    if (poolCoinDetailsBean.getType() == 1) {
                        dataBean = poolCoinDetailsBean.getData();
                        String[] split = dataBean.getMiningUrl().split(",");
                        for (int i = 0; i < split.length; i++) {
                            if (i == 0) {
                                tv_address1.setText("" + split[i]);
                            }
                            if (i == 1) {
                                tv_address2.setText("" + split[i]);


                            }
                            if (i == 2) {
                                tv_address3.setText("" + split[i]);


                            }
                        }
                        if (split.length == 1 || split.length == 0) {
                            ll_address2.setVisibility(View.GONE);
                            ll_address3.setVisibility(View.GONE);

                        }
                        if (split.length == 2) {
                            ll_address2.setVisibility(View.VISIBLE);
                            ll_address3.setVisibility(View.GONE);
                        }
                        if (split.length == 3) {
                            ll_address2.setVisibility(View.VISIBLE);
                            ll_address3.setVisibility(View.VISIBLE);
                        }

                        if (dataBean.getPrompt()==null||"".equals(dataBean.getPrompt()))
                        {
                            ll_Prompt.setVisibility(View.GONE);
                        }else {
                            ll_Prompt.setVisibility(View.VISIBLE);
                            tv_Prompt.setText(dataBean.getPrompt());
                        }


                        tv_NetworkHashrate.setText(dataBean.getNetworkHashrate());
                        tv_PoolHashrate.setText(dataBean.getPoolHashrate());
                        tv_NetworkDifficulty.setText(dataBean.getNetworkDifficulty());


                        tv_dayunit.setText("每" + dataBean.getThroughputUnit() + "日理论收益");
                        tv_dayunit.requestLayout();
                        double t = dataBean.getThroughput() * dataBean.getPrice();//美元的日理论收益
                        if (spUtil.getInt(BaseApplication.MONEYKIND, 0) == 1) {
                            BigDecimal bi1 = new BigDecimal(dataBean.getPrice());

                            BigDecimal bi2 = new BigDecimal(dataBean.getExchange() + "");
                            double s = bi1.multiply(bi2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                            BigDecimal bi3 = new BigDecimal(t);
                            double f = bi3.multiply(bi2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                            //人民币币价
                            tv_Price.setText("￥" + new DecimalFormat("0.00").format(s));
                            tv_Throughput.setText(Util.GetNumber(dataBean.getThroughput() + "") + " " + dataBean.getCode() + "≈￥" + new DecimalFormat("0.00").format(f));

                        } else if (spUtil.getInt(BaseApplication.MONEYKIND, 0) == 2) {
                            //美元
                            tv_Price.setText("$" + new DecimalFormat("0.00").format(dataBean.getPrice()));


                            tv_Throughput.setText(Util.GetNumber(dataBean.getThroughput() + "") + " " + dataBean.getCode() + "≈$" + new DecimalFormat("0.00").format(t));
                        }

                        tv_CostRate.setText(dataBean.getCostRate());
                        tv_StartPayAmount.setText(dataBean.getStartPayAmount());
                        tv_PayTime.setText(dataBean.getPayTime());


                    }
                }

                @Override
                public void onError(String msg) {
                    super.onError(msg);


                    ToastUtil.showToast(getActivity(), msg);
                }
            });


            //中间子帐号信息
            NetHelperNew.PoolAccountInfo("" + currencyId, "" + childaccountId, new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                    Log.i("-->", "子帐号信息详情数据：" + data);

                    PoolAccountInfoBean poolAccountInfoBean = MyGson.getInstance().fromJson(data, PoolAccountInfoBean.class);


                    if (poolAccountInfoBean.getType() == 1) {
                        PoolAccountInfoBean.DataBean data1 = poolAccountInfoBean.getData();
                        tv_onlinenum.setText("" + data1.getOnMinerNumber());
                        tv_OffMinerNumber.setText("" + data1.getOffMinerNumber());
                        String[] s = data1.getHashrate24H().split(" ");
                        if (s.length == 2) {
                            tv_Hashrate24H.setText("" + s[0]);
                            tv_Hashrate24H.requestLayout();
                            tv_Hashrate24Hunit.setText("" + s[1]);
                        }

                        tv_Profit24H.setText(Util.GetNumber(data1.getProfit24H() + ""));
                        tv_Balance.setText(Util.GetNumber(data1.getBalance() + ""));
                        tv_unit1.setText("" + tv_currrncyname.getText().toString());
                        tv_unit2.setText("" + tv_currrncyname.getText().toString());
                    }
                }

                @Override
                public void onError(String msg) {
                    super.onError(msg);


                    ToastUtil.showToast(getActivity(), msg);
                }
            });

        }

    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.i("-->", "===================setUserVisibleHint");
        if (dataBean != null) {

            double t = dataBean.getThroughput() * dataBean.getPrice();//美元的日理论收益
            if (spUtil.getInt(BaseApplication.MONEYKIND, 0) == 1) {
                BigDecimal bi1 = new BigDecimal(dataBean.getPrice());

                BigDecimal bi2 = new BigDecimal(dataBean.getExchange() + "");
                double s = bi1.multiply(bi2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                BigDecimal bi3 = new BigDecimal(t);
                double f = bi3.multiply(bi2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                //人民币币价
                tv_Price.setText("￥" + new DecimalFormat("0.00").format(s));
                tv_Throughput.setText(Util.GetNumber(dataBean.getThroughput() + "") + " " + dataBean.getCode() + "≈￥" + new DecimalFormat("0.00").format(f));

            } else if (spUtil.getInt(BaseApplication.MONEYKIND, 0) == 2) {
                //美元
                tv_Price.setText("$" + new DecimalFormat("0.00").format(dataBean.getPrice()));


                tv_Throughput.setText(Util.GetNumber(dataBean.getThroughput() + "") + " " + dataBean.getCode() + "≈$" + new DecimalFormat("0.00").format(t));
            }
        }

    }

    private void initSwitcher() {
        mywitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    //选中状态 可以做一些操作
                    //未选中状态 可以做一些操作
                    //合计
                    tv_day.setTextColor(getResources().getColor(R.color.system_color));
                    tv_minue.setTextColor(getResources().getColor(R.color.white));

                    getChildaccount();
                } else {
                    tv_minue.setTextColor(getResources().getColor(R.color.system_color));
                    tv_day.setTextColor(getResources().getColor(R.color.white));
                    getData();
                }
            }


        });

    }
    //获取子账户
    private void getChildaccount() {
        if (NetWorkUtil.check(getActivity())) {

                loadingDialog.show();
            NetHelperNew.GetChildAccount(currencyId + "", new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                    loadingDialog.dismiss();
                    Log.i("-->", "矿池子账户列表：" + data);
                    ChildAccountBean childAccountBean = MyGson.getInstance().fromJson(data, ChildAccountBean.class);
                    if (childAccountBean.getType() == 1) {

                    } else {
                        ToastUtil.showToast(getActivity(), childAccountBean.getContent());

                    }
                }

                @Override
                public void onError(String msg) {
                    super.onError(msg);
                    loadingDialog.dismiss();

                    ToastUtil.showToast(getActivity(), msg);
                }
            });


        }

    }
    @OnClick({R.id.mywitcher, R.id.iv_china, R.id.iv_usa, R.id.iv_ou, R.id.iv_tips, R.id.ll_menu, R.id.ll_currency, R.id.btn_fastlook})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_menu:
                //弹出抽屉
                onSelectPersonListener.selectPersonLayout(2, childaccountId);
                break;
            case R.id.btn_fastlook:
                if (onSelectPersonListener.getIsFastLogin()) {
                    //返回登录账户
                    onSelectPersonListener.selectPersonLayout(5, 0);
                } else {
                    //快速查看
                    startActivityForResult(new Intent(getContext(), FastLookActivity.class), 12);
                }


                break;
            case R.id.mywitcher:
                //选择天数类型

                break;
            case R.id.iv_china:
                //复制中国区挖矿地址
                ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                cmb.setText(tv_address1.getText().toString().trim());
                ToastUtil.showToast(getActivity(), "已复制到剪贴板");
                break;
            case R.id.iv_usa:
                //复制美国区挖矿地址
                ClipboardManager cmb2 = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                cmb2.setText(tv_address2.getText().toString().trim());
                ToastUtil.showToast(getActivity(), "已复制到剪贴板");
                break;
            case R.id.iv_ou:
                //复制欧洲挖矿地址
                ClipboardManager cmb3 = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                cmb3.setText(tv_address3.getText().toString().trim());
                ToastUtil.showToast(getActivity(), "已复制到剪贴板");
                break;
            case R.id.iv_tips:
                //余额提示
                Util.showSnackBar(getActivity(), "余额提示");
                break;
            case R.id.ll_currency:
                //选择币种
                if (currencyPopupWindow != null)
                    currencyPopupWindow.showAsDropDown(ll_currency, 0, 0);
                break;

        }
    }

    // 当FRagmen被加载到activity的时候会被回调
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if (activity instanceof OnSelectPersonListener) {
            onSelectPersonListener = (OnSelectPersonListener) activity; // 2.2 获取到宿主activity并赋值
        } else {
            throw new IllegalArgumentException("activity must implements FragmentInteraction");
        }
    }

    //把传递进来的activity对象释放掉
    @Override
    public void onDetach() {
        super.onDetach();
        onSelectPersonListener = null;
    }

    private void initTextSwitcher() {
        List<String> texts = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            texts.add("循环....." + i);
        }
        textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                final TextView t = new TextView(getActivity());
                t.setTextColor(getResources().getColor(R.color.white));
                t.setSingleLine();
                t.setEllipsize(TextUtils.TruncateAt.END);
                //内容的点击事件
                t.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getActivity(), t.getText().toString(), Toast.LENGTH_SHORT).show();
                    }
                });

                return t;
            }
        });
        new TextSwitcherAnimation(textSwitcher, texts).create();

    }

    /**
     * 子账户改变
     *
     * @param type
     * @param name
     * @param id
     */
    @Override
    public void updatePerson(int type, String name, int id) {

        if (type == 1) {
            tv_person.setText("合计");
            childaccountId = MainActivity.TOTALID;
            getData();
        } else {
            tv_person.setText(name);
            childaccountId = id;
        }

       if (type==6)
       {
           //矿池页
           getData();
       }


        Log.i("-->", type + "OrderPoolfragment" + name);
        if (type == 3) {
            //快速登录
            btn_fastlook.setText("返回登录账号");
            iv_account.setImageDrawable(getActivity().getResources().getDrawable(R.mipmap.daohang2));
            tv_person.setText(name + " （只读页面）");
        } else {
            btn_fastlook.setText("快速查看");
            iv_account.setImageDrawable(getActivity().getResources().getDrawable(R.mipmap.daohang));
        }
    }

    /**
     * 修改币种
     *
     * @param img
     * @param name
     * @param id
     */
    @Override
    public void updateCurrency(int img, String name, int id) {
        currencyId = id;
        for (int i = 0; i < currencyListData.size(); i++) {
            if (currencyListData.get(i).getId() == id) {
                GlideUtil.loadImage(getActivity(), NetHelperNew.URL + currencyListData.get(i).getIcon(), iv_curreney, R.mipmap.failimage, R.mipmap.failimage);
                tv_currrncyname.setText(currencyListData.get(i).getCode().toUpperCase());
            }
        }
//        getData();
    }

    /**
     * 页面刷新
     *
     * @param type
     */
    @Override
    public void fragmentRefresh(int type) {

//        getData();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
